home *** CD-ROM | disk | FTP | other *** search
/ Atari Mega Archive 1 / Atari Mega Archive - Volume 1.iso / telecomm / sticpsrc.lzh / SOURCE.ARC / AX25CMD.C < prev    next >
C/C++ Source or Header  |  1990-08-12  |  22KB  |  1,004 lines

  1. #include <stdio.h>
  2. #include "global.h"
  3. #include "mbuf.h"
  4. #include "ax25.h"
  5. #include "timer.h"
  6. #include "iface.h"
  7. #include "lapb.h"
  8. #include "cmdparse.h"
  9. #include "session.h"
  10.  
  11. char *ax25states[] = {
  12.     "Disconnected",
  13.     "Conn pending",
  14.     "Disc pending",
  15.     "Connected",
  16.     "Frame Reject"
  17. };
  18.  
  19. char *ax25mesgs[] = {
  20.     "",
  21.     "CONNECTED to",
  22.     "DISCONNECTED from",
  23.     "BUSY from",
  24.     "LINK FAILURE with",
  25.     "LINK RESET from",
  26.     "LINK RESET to",
  27.     "FRAME REJECT from",
  28.     "FRAME REJECT to",
  29. };
  30.  
  31. char badcall[] = "Bad callsign %s\n";
  32. char baddigi[] = "Bad digi callsign %s\n";
  33. char notax25[] = "Interface %s not AX.25 type\n";
  34.  
  35. static char all_ax[] = "ALL AX.25";
  36. static char conn[] = "conn";
  37. static char digi[] = "digi";
  38. static char gate[] = "gate";
  39. static char on[] = "on";
  40. static char off[] = "off";
  41. static char stop[] = "stop";
  42.  
  43. extern char nospace[];
  44.  
  45. static int doaxport(),dodigipeat(),doaxstat(),dot1(),dot2(),dot3(),dot4(),
  46.     doexclude(),dopthresh(),domaxframe(),doaxwindow(),dopaclen(),don2(),
  47.     doaxclose(),doaxdisc(),doaxreset(),doaxkick(),doaxbreak(),domaxsamml();
  48. int dopersist();
  49.  
  50. int doaxstart(),doaxstop();
  51.  
  52. static struct cmds axcmds[] = {
  53. #ifdef AX25BREAK
  54.     "break",    doaxbreak,    4, "<iface> <call1> <call2> [<digi>]", NULLCHAR,
  55. #endif
  56.     "close",    doaxclose,    2, "<axcb>", NULLCHAR,
  57.     "digipeat",    dodigipeat,    0, NULLCHAR,    NULLCHAR,
  58.     "disconnect",    doaxdisc,    2, "<axcb>", NULLCHAR,
  59.     "exclude",    doexclude,    0, NULLCHAR,    NULLCHAR,
  60.     "kick",        doaxkick,    2, "<axcb>", NULLCHAR,
  61.     "maxframe",    domaxframe,    0, NULLCHAR,    NULLCHAR,
  62.     "maxsammler",    domaxsamml,    0, NULLCHAR,    NULLCHAR,
  63.     "paclen",    dopaclen,    0, NULLCHAR,    NULLCHAR,
  64.     "persist",    dopersist,    0, NULLCHAR,    NULLCHAR,
  65.     "port",        doaxport,    0, NULLCHAR,    "Couldn't set port",
  66.     "pthresh",    dopthresh,    0, NULLCHAR,    NULLCHAR,
  67.     "reset",    doaxreset,    2, "<axcb>", NULLCHAR,
  68.     "retry",    don2,        0, NULLCHAR,    NULLCHAR,
  69.     "status",    doaxstat,    0, NULLCHAR,    NULLCHAR,
  70.     "start",    doaxstart,    2, "<servername>",NULLCHAR,
  71.     "stop",        doaxstop,    2, "<servername>", NULLCHAR,
  72.     "t1",        dot1,        0, NULLCHAR,    NULLCHAR,
  73.     "t2",        dot2,        0, NULLCHAR,    NULLCHAR,
  74.     "t3",        dot3,        0, NULLCHAR,    NULLCHAR,
  75.     "t4",        dot4,        0, NULLCHAR,    NULLCHAR,
  76.     "window",    doaxwindow,    0, NULLCHAR,    NULLCHAR,
  77.     NULLCHAR,    NULLFP,        0, "?subcommands", NULLCHAR
  78. };
  79. /* Multiplexer for top-level ax25 command */
  80. doax25(argc,argv)
  81. int argc;
  82. char *argv[];
  83. {
  84.     return subcmd(axcmds,argc,argv);
  85. }
  86.  
  87. /* Reset an AX.25 session */
  88. static
  89. doaxreset(argc,argv)
  90. int argc;
  91. char *argv[];
  92. {
  93.     struct ax25_cb *axp;
  94.     extern char notval[];
  95.  
  96.     axp = (struct ax25_cb *)long2ptr(htol(argv[1]));
  97.     if(!ax25val(axp)){
  98.         printf(notval);
  99.         return 1;
  100.     }
  101.     reset_ax25(axp);
  102.     return 0;
  103. }
  104.  
  105. /* Close an AX.25 session (= graceful disconnect) */
  106. static
  107. doaxclose(argc,argv)
  108. int argc;
  109. char *argv[];
  110. {
  111.     struct ax25_cb *axp;
  112.     void close_ax25();
  113.     extern char notval[];
  114.  
  115.     axp = (struct ax25_cb *)long2ptr(htol(argv[1]));
  116.     if(!ax25val(axp)){
  117.         printf(notval);
  118.         return 1;
  119.     }
  120.     close_ax25(axp);
  121.     return 0;
  122. }
  123.  
  124. /* Disconnect an AX.25 session */
  125. static
  126. doaxdisc(argc,argv)
  127. int argc;
  128. char *argv[];
  129. {
  130.     struct ax25_cb *axp;
  131.     void disc_ax25();
  132.     extern char notval[];
  133.  
  134.     axp = (struct ax25_cb *)long2ptr(htol(argv[1]));
  135.     if(!ax25val(axp)){
  136.         printf(notval);
  137.         return 1;
  138.     }
  139.     disc_ax25(axp);
  140.     return 0;
  141. }
  142.  
  143. #ifdef AX25BREAK
  144. /* Breakdown an AX.25 connection */
  145. /* This really anti-social function was only implemented to stop BBS */
  146. /* systems from forwarding huge amounts of mail using AX.25 when the */
  147. /* channel already is very busy.  Probably can be removed soon (??)  */
  148.  
  149. static int
  150. doaxbreak(argc,argv)
  151. int argc;
  152. char *argv[];
  153. {
  154.     struct ax25_cb axcb;
  155.     extern char nospace[];
  156.  
  157.     memset(&axcb,0,sizeof(struct ax25_cb));
  158.  
  159.     if((axcb.interface = ifunit(argv[1])) == NULLIF)
  160.         return 1;
  161.     if(!(axcb.interface->flags & IF_AX25)){
  162.         printf(notax25,argv[1]);
  163.         return 1;
  164.     }
  165.     if(setcall(&axcb.addr.source,argv[2]) < 0){
  166.         printf(badcall,argv[2]);
  167.         return 1;
  168.     }
  169.     if(setcall(&axcb.addr.dest,argv[3]) < 0){
  170.         printf(badcall,argv[3]);
  171.         return 1;
  172.     }
  173.     axcb.addr.ndigis = 0;
  174.     if(argc > 4){
  175.         if(setcall(&axcb.addr.digis[0],argv[4]) < 0){
  176.             printf(baddigi,argv[4]);
  177.             return 1;
  178.         }
  179.         axcb.addr.ndigis = 1;
  180.     }
  181.     sendctl(&axcb,COMMAND,DISC|PF);
  182.     sendctl(&axcb,RESPONSE,DM|PF);
  183.     setcall(&axcb.addr.source,argv[3]);
  184.     setcall(&axcb.addr.dest,argv[2]);
  185.     sendctl(&axcb,COMMAND,DISC|PF);
  186.     sendctl(&axcb,RESPONSE,DM|PF);
  187.     stop_timer(&axcb.t1);
  188.     return 0;
  189. }
  190. #endif
  191.  
  192. /* Display AX.25 link level control blocks */
  193. static
  194. doaxstat(argc,argv)
  195. int argc;
  196. char *argv[];
  197. {
  198.     register int i;
  199.     register struct ax25_cb *axp;
  200.     char tmps[10],tmpd[10];
  201.     extern char notval[];
  202.  
  203.     if(argc < 2){
  204.         printf("    &AXB IF    Rcv-Q   Snd-Q   Local     Remote    State\n");
  205.         for(i=0;i<NHASH;i++){
  206.             for(axp = ax25_cb[i];axp != NULLAX25; axp = axp->next){
  207.                 pax25(tmps,&axp->addr.source);
  208.                 pax25(tmpd,&axp->addr.dest);
  209.                 printf("%8lx %-6s%5d%8d   %-10s%-10s%s\n",
  210.                     ptr2long(axp),axp->interface->name,
  211.                     len_mbuf(axp->rxq),len_q(axp->txq),
  212.                     tmps,tmpd,ax25states[axp->state]);
  213.             }
  214.         }
  215.         return 0;
  216.     }
  217.     axp = (struct ax25_cb *)long2ptr(htol(argv[1]));
  218.     if(!ax25val(axp)){
  219.         printf(notval);
  220.         return 1;
  221.     }
  222.     dumpstat(axp);
  223.     return 0;
  224. }
  225. /* Dump one control block */
  226. static
  227. dumpstat(axp)
  228. register struct ax25_cb *axp;
  229. {
  230.     char tmps[10],tmp[10];
  231.     int i;
  232.  
  233.     if(axp == NULLAX25 || axp->interface == NULLIF)
  234.         return;
  235.     printf("    &AXB IF   Local     Remote    RBWF V(S) V(R) Unack P Retry State\n");
  236.     pax25(tmps,&axp->addr.source);
  237.     pax25(tmp,&axp->addr.dest);
  238.     printf("%8lx %-5s%-10s%-10s",ptr2long(axp),axp->interface->name,tmps,tmp);
  239.     putchar(axp->rejsent ? 'R' : ' ');
  240.     putchar(axp->remotebusy ? 'B' : ' ');
  241.     putchar(axp->waitack ? 'W' : ' ');
  242.     putchar(axp->fin ? 'F' : ' ');
  243.     printf(" %4d %4d",axp->vs,axp->vr);
  244.     printf(" %u/%u/%u %u",axp->unack,axp->sent,axp->maxframe,axp->proto);
  245.     printf(" %02u/%02u",axp->retries,axp->n2);
  246.     printf(" %s\n",ax25states[axp->state]);
  247.  
  248.     printf("T1: ");
  249.     if(run_timer(&axp->t1))
  250.         printf("%lu",TICK2MS(axp->t1.start - axp->t1.count));
  251.     else
  252.         printf(stop);
  253.     printf("/%lu ms; ",TICK2MS(axp->t1.start));
  254.  
  255.     printf("T2: ");
  256.     if(run_timer(&axp->t2))
  257.         printf("%lu",TICK2MS(axp->t2.start - axp->t2.count));
  258.     else
  259.         printf(stop);
  260.     printf("/%lu ms; ",TICK2MS(axp->t2.start));
  261.  
  262.     printf("T3: ");
  263.     if(run_timer(&axp->t3))
  264.         printf("%lu",TICK2MS(axp->t3.start - axp->t3.count));
  265.     else
  266.         printf(stop);
  267.     printf("/%lu ms; ",TICK2MS(axp->t3.start));
  268.  
  269.     printf("T4: ");
  270.     if(run_timer(&axp->t4))
  271.         printf("%lu",TICK2MS(axp->t4.start - axp->t4.count));
  272.     else
  273.         printf(stop);
  274.     printf("/%lu ms",TICK2MS(axp->t4.start));
  275.  
  276.     for(i = 0; i < 8; i++)
  277.         if(axp->sammlq[i] != NULLBUF){
  278.             printf("\nFramesammler: %d",i++);
  279.             for(; i < 8; i++)
  280.                 if(axp->sammlq[i] != NULLBUF)
  281.                     printf(" %d",i);
  282.             printf(" (max %d)",axp->maxsamml);
  283.         }
  284.  
  285.     if(axp->addr.ndigis != 0){
  286.         printf("\nDigipeaters:");
  287.         for(i=0;i<axp->addr.ndigis;i++){
  288.             pax25(tmp,&axp->addr.digis[i]);
  289.             printf(" %s",tmp);
  290.         }
  291.     }
  292.     printf("\n");
  293. }
  294.  
  295. /* Display or change our AX.25 ports
  296.  * usage:
  297.  * ax25 port <portnumber> conn|digi <callsign> [<interface> [gate|multi]]
  298.  * ax25 port
  299.  */
  300. static
  301. doaxport(argc,argv)
  302. int argc;
  303. char *argv[];
  304. {
  305.     register struct ax25_call *axc;
  306.     struct ax25_call **which;
  307.     struct interface *ifp = NULLIF;
  308.     struct ax25_addr mycall;
  309.     char tmp[10];
  310.     int port;
  311.     void ax_noserv();
  312.  
  313.     if(argc < 2){
  314.         printf("port#  Callsign   Interface  Mode  MG  Started\n");
  315.         if((axc = ax25_port) != NULLAXCALL)
  316.             while(axc->p_next != NULLAXCALL)
  317.                 axc = axc->p_next;
  318.  
  319.         while(axc != NULLAXCALL){
  320.             pax25(tmp,&axc->addr);
  321.             printf("%4d   %-10s %-10s %-6s%c%c  ",axc->port,tmp,
  322.                   (axc->interface == NULLIF?
  323.                     all_ax:axc->interface->name),
  324.                   (axc->mode == CONNECT? conn:digi),
  325.                   (axc->flags & MULTI_IF? 'M':' '),
  326.                   (axc->flags & DIGIGATEWAY? 'G':' '));
  327.  
  328.             if(axc->s_upcall == ax_noserv)
  329.                 printf("no\n");
  330.             else
  331.                 printf("yes\n");
  332.  
  333.             axc = axc->p_prev;
  334.         }
  335.         return 0;
  336.     }
  337.  
  338.     if(argc < 4){
  339.         pr